/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package circulo;

import processing.core.*;

/**
 *
 * @author DAVINCI
 */
public class Circulo extends PApplet {

    int xStart, x0,y0;
    int yStart;
    int xEnd;
    int yEnd;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PApplet.main(new String[]{"circulo.Circulo"});
    }

    void PuntosCirculo(int x, int y, int radio) {
//        xStart += radio;
//        yStart += radio;
        point(x + xStart, y + yStart);
        point(y + xStart, x + yStart);
        point(y + xStart, -x + yStart);
        point(x + xStart, -y + yStart);
        point(-x + xStart, -y + yStart);
        point(-y + xStart, -x + yStart);
        point(-y + xStart, x + yStart);
        point(-x + xStart, y + yStart);

    }

    void CirculoBresenham(int radio) {
        int x = 0;
        int y = radio;
        PuntosCirculo(x, y, radio);
        float d = (float) 5.0 / (float) 4.0 - radio;
        while (y > x) {
            if (d < 0) {
                d += 2 * x + 3; //selecciona E
            } else {//selecciona SE
                d += 2 * (x - y) + 5;
                y--;
            }
            x++;
            PuntosCirculo(x, y, radio);
        }


    }

    @Override
    public void setup() {
        size(800, 600);
        background(200);

    }

    @Override
    public void draw() {
    }

    @Override
    public void mousePressed() {
        xStart =x0= mouseX;
        yStart =y0= mouseY;

    }

    @Override
    public void mouseDragged() {
        background(200);
        xEnd = mouseX;
        yEnd = mouseY;
        int radio;
        int dx = xEnd - x0;
        int dy = yEnd - y0;
        if (abs(dx) > abs(dy)) {
            radio = abs(dy);
        } else {
            radio = abs(dx);
        }

        CirculoBresenham(radio);
//        BresenhamLine(5, 8,90,90);
    }
}
